<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
            list-style: none;
        }
        .banner {
            width: 300px;
            height: 200px;
            margin: 50px auto;
            position: relative;
        }
        .banner ul li {
            width: 300px;
            height: 200px;
            text-align: center;
            line-height: 200px;
            position: absolute;
            left: 0;
            top: 0;
            background-color: #f00;
            opacity: 0;
            transition: 1s;
        }
        .banner .on {
            opacity: 1;
        }
        .banner ol {
            position: absolute;
            width: 100%;
            display: flex;
            justify-content: center;
            bottom: 0;
        }
        .banner ol li {
            width: 20px;
            height: 20px;
            background-color: #ff0;
            margin: 10px;
        }
        .banner .show {
            background-color: #fff;
        }
    </style>
</head>
<body>
    <div class="banner">
        <ul>
            <li class="on">1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>
        </ul>
        <ol>
            <li class="show"></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ol>
    </div>


    <script>

        var oUlLis = document.querySelectorAll('ul li') ;
        var oOlLis = document.querySelectorAll('ol li') ;

        var index = 0 ;  // 第几张

        var t ; // 定时器

        autoPlay() ;

        for(var i = 0 ; i < oOlLis.length ; i++) {
            oOlLis[i].index = i ;
            oOlLis[i].onclick = function() {
                clearInterval(t) ;
                // index = this？  对应的下标
                index = this.index ;
                show() ;
                autoPlay() ;
            }
           
        }




        function autoPlay() {
            t = setInterval(function(){
                index++ ; 
                if(index === oUlLis.length) {
                    index = 0 ;
                }
                show() ;
            } , 1000)
        }


        function show() {
            // 清除所有， 显示当前
            for(var i = 0 ; i < oUlLis.length ; i++) {
                oUlLis[i].classList.remove('on') ;
                oOlLis[i].classList.remove('show') ;
            }
            oUlLis[index].classList.add('on') ;
            oOlLis[index].classList.add('show') ;
        }

    </script>
</body>
</html>